/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Apresentacao.java
 *
 * Created on 02/12/2011, 16:49:51
 */
package Formularios;

import Atributos.DadosStatic;
import Metodos.MinimizaTela;
import Metodos.ObjetoMet;
import com.sun.awt.AWTUtilities;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;

/**
 *
 * @author ARMTEC
 */
public class Apresentacao extends javax.swing.JFrame {
    static int quantresg;
ObjetoMet objmet=new ObjetoMet();
DadosStatic ds= new DadosStatic();
MinimizaTela tela= new MinimizaTela();  

    /** Creates new form Apresentacao */
    public Apresentacao() {
         try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormHorasAula.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        initComponents();
        

//        File dir = new File("C:/ok");
//        if(dir.mkdir()){
//            System.out.println("okkk");
//        }
        BufferedImage image=null;
        File imageFile=new File(".\\src\\Imagens\\logo3.png");
        try {
            image=ImageIO.read(imageFile);
            
        } catch (IOException ex) {
        }
        this.setIconImage(image);
        
        try {
             quantresg=objmet.QuatRegistro();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        try {
            objmet.DeletarTabHorarioTabRelProf();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println(quantresg);
        if(objmet.HouverDados()){
            jLabel2.setVisible(false);
            jLabel1.setEnabled(false);
            this.setEnabled(false);
            
       timer2.start();
        timer1.start();
        }else{
            
            jProgressBar1.setVisible(false);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        timer1 = new org.netbeans.examples.lib.timerbean.Timer();
        timer2 = new org.netbeans.examples.lib.timerbean.Timer();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        timer1.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer1OnTime(evt);
            }
        });

        timer2.setOnceOnly(true);
        timer2.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer2OnTime(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SGH (Sistema Gerenciador de Horários)");
        setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        setIconImages(null);
        setResizable(false);
        getContentPane().setLayout(null);

        jProgressBar1.setBackground(new java.awt.Color(0, 0, 0));
        jProgressBar1.setForeground(new java.awt.Color(0, 0, 0));
        getContentPane().add(jProgressBar1);
        jProgressBar1.setBounds(390, 588, 540, 10);

        jLabel2.setFont(new java.awt.Font("D3 Euronism", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 102, 0));
        jLabel2.setText("Clique na tela para prosseguir");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(580, 570, 380, 30);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/apresentaçao.gif"))); // NOI18N
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 1025, 619);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-981)/2, (screenSize.height-647)/2, 981, 647);
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        try {
            tela.Minimiza(0);
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
       
       java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ChamaLayout().setVisible(true);
            }
        }); 
 dispose();
    }//GEN-LAST:event_jLabel1MouseClicked

    private void timer1OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer1OnTime
       int value=(DadosStatic.getDadosinsersos()*100)/quantresg;
        jProgressBar1.setValue(value);
        if(value>jProgressBar1.getMaximum()){
            jProgressBar1.setValue(jProgressBar1.getMaximum());
        }
    }//GEN-LAST:event_timer1OnTime

    private void timer2OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer2OnTime
       
        if(objmet.HouverDados()){
            
            jLabel2.setVisible(false);
           
               TransfereDados();
               
            jLabel1.setEnabled(true);
            jProgressBar1.setVisible(false);
            jLabel2.setVisible(true);
            this.setEnabled(true);
            
        }else{
    jProgressBar1.setVisible(false);
    jLabel2.setVisible(true);
}
    }//GEN-LAST:event_timer2OnTime

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Apresentacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Apresentacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Apresentacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Apresentacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Apresentacao().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JProgressBar jProgressBar1;
    private org.netbeans.examples.lib.timerbean.Timer timer1;
    private org.netbeans.examples.lib.timerbean.Timer timer2;
    // End of variables declaration//GEN-END:variables

    private void TransfereDados()  {
        DadosStatic.setDadosinsersos(0);
        try {
            objmet.DeletarTabHorarioTabRelProf();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            objmet.DeletaTabHA();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        try {
            objmet.RepassapraTab1();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            objmet.RepassapraTab1DiasAulas();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            objmet.RepassapraTab1prof();
        } catch (SQLException ex) {
            Logger.getLogger(Apresentacao.class.getName()).log(Level.SEVERE, null, ex);
        }
            
    }
}
